package org.ntu.rtsearch.store;

import java.io.Serializable;
import java.util.ArrayList;

public class RAMFile implements Serializable{

	private static final long serialVersionUID = 12;
	
	protected ArrayList<byte[]> buffers = new ArrayList<byte[]>();

	long length;
	
	protected long sizeInBytes;
	
	public long lastModify = System.currentTimeMillis();

	public synchronized long getLength() {
		return length;
	}


	public synchronized void setLength(long length) {
		this.length = length;
	}


	public synchronized long getLastModify() {
		return lastModify;
	}


	public synchronized void setLastModify(long lastModify) {
		this.lastModify = lastModify;
	}


	public synchronized long getSizeInBytes() {
		return sizeInBytes;
	}
	
	public final byte[] addBuffer(int size) {
		byte[] buffer = new byte[size];
		
		synchronized (this) {
			buffers.add(buffer);
			sizeInBytes += size;
		}
		
		return buffer;
	}
	
	protected final synchronized byte[] getBuffer(int index) {
		return buffers.get(index);
	}
	
	protected final synchronized int numBuffers() {
		return buffers.size();
	}
}
